from langchain_neo4j import Neo4jGraph
import os
from dotenv import load_dotenv


class PersonNodeService:
    def __init__(self):
        load_dotenv()
        self.graph = Neo4jGraph(url=os.getenv("NEO4J_URI"), username=os.getenv("NEO4J_USER"),
                                password=os.getenv("NEO4J_PASSWORD"))

    # 创建节点
    def create_node(self, **kwargs):
        # 创建cypher语句
        cypher_str = "CREATE (p:Person {name:$name,age:$age,city:$city,occupation:$occupation})"
        self.graph.query(cypher_str, params=kwargs)

    # 查询节点
    def query_node(self, **kwargs):
        cypher_str = "MATCH (p:Person) return p"
        rs = self.graph.query(cypher_str)
        print(rs)
        return rs


if __name__ == '__main__':
    person_node_service = PersonNodeService()
    # person_node_service.create_node(name="张三",age=18,city="上海",occupation="学生")
    rs = person_node_service.query_node()
